package com.berchen.数据结构.栈;

/**
 * 链表实现栈
 */
public class LinketStack {

    private Node head;

    public LinketStack() {
    }

    public boolean isEmpty(){
        return head==null;
    }
    public void push(Node node){
        if(isEmpty()){
            head=node;
            return;
        }
        node.next=head;
        head=node;
    }
    public Node pop(){
        if(isEmpty())throw new RuntimeException("栈空");
        Node temp=head;
        head=head.next;
        return temp;
    }
    public void list(){
        Node temp=head;
        while (temp!=null){
            System.out.println(temp);
            temp=temp.next;
        }
    }
}
